#!/usr/bin/perl

use strict;
use warnings;

# will filter EOF messages from cmp
my $filterEOF = 1;

my @diffs;

# copy common files used by both MAINPLAY and SUBPLAY
system("cp MAINPLAY/DIVIDE.ASM SUBPLAY/DIVIDE.ASM");
system("cp MAINPLAY/NUMSTR.ASM SUBPLAY/NUMSTR.ASM");
system("cp MAINPLAY/HEXSTR.ASM SUBPLAY/HEXSTR.ASM");
system("cp MAINPLAY/APRINT.ASM SUBPLAY/APRINT.ASM");

# run the gpp and an assembler on each revision
foreach my $type ('MAINPLAY','SUBPLAY') {
    foreach my $original (<ORIGINAL/*/$type.BIN>) {
	if ( $original =~ /[\\\/](([0-9]+)(_[0-9]+)?)[\\\/]/ ) {
	    my $target = $1;
	    my $revision = $2;
	    if ( $target eq '19931207_2' ) {
		$revision = '19930506';
	    }
	    system("cd $type ; gpp -DREVISION=$revision $type.ASM > $target.ASM ; scdasm -v=1 $target.ASM $target.BIN $target.LST");
	    push @diffs, "$original $type/$target.BIN";
	}
    }
}

# now compare the revision with what was assembled
foreach my $diff (@diffs) {
    my $cmd = "cmp $diff";
    if ( $filterEOF ) {
	$cmd .= ' 2>&1 | grep -v EOF';
    }
    system($cmd);
}
